package thread;
//直接继承Thread类创建线程
class MyThread extends Thread {
    @Override
    public void run() {
        //这里要写分代码,就是该线程要完成的工作
        while (true) {
            System.out.println("hello thread");
            //让程序休眠1s
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo1 {
    public static void main(String[] args) {
        Thread t = new MyThread();
        t.start();  //启动线程  相当于创建了新的线程  如果直接调用run()方法就不算创建新的线程

        while (true) {
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
